package jdbc.day01;

import java.sql.*;

public class JdbcDome01 {
    public static void main(String[] args) {
        Connection conn=null;
        PreparedStatement  stat =null;
        try {
            //注册驱动
           Class.forName("com.mysql.jdbc.Driver");
            //创建连接对象
            conn = DriverManager.getConnection(
                    "jdbc:mysql:///test","root","123456");
            //sql语句
            String st="select name from student where id=?";
            //创建执行sql对象
            stat = conn.prepareStatement(st);
            stat.setInt(1,1);
            ResultSet resultSet = stat.executeQuery();
            while (resultSet.next()){
               String name= resultSet.getString(1);
                System.out.println(name);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (stat!=null){
                try {
                    stat.close();
                } catch (Exception throwables) {
                    throwables.printStackTrace();
                }
            }
            if (conn!=null){
                try {
                    conn.close();
                } catch (Exception throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }
}
